﻿using System.IO;
using UnityEngine;

public class PersistentStorage : MonoBehaviour {
    private string savePath;
    private void Awake () {
        savePath = System.IO.Path.Combine (Application.persistentDataPath, "saveFile");
    }

    public void Save (PersistableObject o) {
        using (var write = new BinaryWriter (File.Open (savePath, FileMode.Create))) {
            o.Save (new GameDataWriter (write));
        }
    }

    public void Load (PersistableObject o) {
        using (var reader = new BinaryReader (File.Open (savePath, FileMode.Open))) {
            o.Load (new GameDataRead (reader));
        }
    }
}